package com.vanzo.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.vanzo.contact.Cn2Spell;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

/**
 * Created by tisen on 2018/1/17.
 */

@Entity
public class Contact implements Parcelable, Comparable<Contact> {

    @Id(autoincrement = true)
    private Long id;
    private String name;
    private String unit;
    private String phone;
    private String beidou;

    public Contact() {
    }

    public Contact(String name, String unit, String phone, String beidou) {
        this.name = name;
        this.unit = unit;
        this.phone = phone;
        this.beidou = beidou;
    }

    public Contact(String name) {
        this.name = name;
    }


    protected Contact(Parcel in) {
        name = in.readString();
        unit = in.readString();
        phone = in.readString();
        beidou = in.readString();
    }

    @Generated(hash = 873802085)
    public Contact(Long id, String name, String unit, String phone, String beidou) {
        this.id = id;
        this.name = name;
        this.unit = unit;
        this.phone = phone;
        this.beidou = beidou;
    }

    public static final Creator<Contact> CREATOR = new Creator<Contact>() {
        @Override
        public Contact createFromParcel(Parcel in) {
            return new Contact(in);
        }

        @Override
        public Contact[] newArray(int size) {
            return new Contact[size];
        }
    };

    public String getPinyin() {
        return Cn2Spell.isChinese(name) ? Cn2Spell.converterToFirstSpell(name) : name;
    }

    @Override
    public int compareTo(@NonNull Contact o) {
        return getPinyin().compareTo(o.getPinyin());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(unit);
        dest.writeString(phone);
        dest.writeString(beidou);
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUnit() {
        return this.unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getBeidou() {
        return this.beidou;
    }

    public void setBeidou(String beidou) {
        this.beidou = beidou;
    }
}
